(() => {
  let ele = {};
  ele.option_new = $("#option-new");
  ele.option_room = $("#option-room");
  ele.list_son = $("#list_son");
  ele.empty = $("#empty");
  ele.more = $("#more");
  ele.meiyou = $("#meiyou");
  ele.myrank = $("#myrank");
  let num = 1;
  let page = 1;
  let list = [];
  let obj = {};
  let is_fd = 2;
  // todo点击tabbar切换房产交易1
  ele.option_new.onclick = () => {
    list = [];
    page = 1;
    //? 这个是用来切换我的按钮来筛选
    num = 1;
    is_fd = 2;
    tabBarQie();
    asyncList();
  };
  // todo点击tabbar切换房产拍卖2
  ele.option_room.onclick = () => {
    list = [];
    page = 1;
    num = 2;
    is_fd = 1;
    //? 这个是用来切换我的按钮来筛选
    tabBarQie();
    asyncList();
  };

  tabBarQie();
  // todo判断num为几，就到几
  function tabBarQie() {
    if (num == 1) {
      // ?对下面的按钮做显示隐藏处理
      ele.option_new.classList.add("option-active");
      ele.option_room.classList.remove("option-active");
    } else if (num == 2) {
      // ?对下面的按钮做显示隐藏处理
      ele.option_room.classList.add("option-active");
      ele.option_new.classList.remove("option-active");
    }
  }

  // !发送请求
  asyncList();
  function asyncList() {
    let token = getCookie("token");
    ajax({
      method: "get",
      url: API_PATH.PAILIST,
      header: {
        Authorization: token,
      },
      data: {
        page: page,
        // size: 1,
        is_fd: is_fd,
      },
      success: (res) => {
        if (res.code == 1) {
          obj = res.data.detail;
          list = [...list, ...res.data.ph_list.data];
          if (list.length === 0) {
            page = 0;
            ele.more.style.display = "none";
            ele.empty.style.display = "block";
          } else {
            initList();
            page++;
            if (page > res.data.ph_list.last_page) {
              ele.more.innerText = "没有更多了";
              ele.more.onclick = null;
            } else {
              ele.more.innerText = "加载更多";
              ele.more.onclick = () => asyncList(page);
            }
          }
        } else openTips(res.msg);
        // obj = res.data.detail;
        // list = [...list, ...res.data.list.data];
        initList();
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }

  initList();
  function initList() {
    // 渲染底部自己值
    ele.myrank.innerHTML = `
    <div class="my1">
    <img src="${
      obj.agent && obj.agent.head_pic
        ? IMG_DOMAIN + obj.agent.head_pic
        : obj.agent && obj.agent.sex == 1
        ? "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png"
        : "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx2.png"
    }"  alt="" />
    <p>我的豪华值：<span>${obj.my_luxury}</span></p>
  </div>
  <div class="my2">
    <p>排名：</p>
    <span>${obj.my_luxury == 0 ? "无" : obj.my_ph}</span>
  </div>`;
    let newList = list
      .map((item, index) => {
        if (index <= 2) {
          return ` <div class="list">
        <div class="left">
          <img src="http://img.qxgs.cc/tiantianlaishouzu/img/wealth/rank${index + 1}.png" alt="" />
        </div>
        <div class="center">
          <div class="centerin">
            <img src="${
              item.detail && item.detail.head_pic
                ? IMG_DOMAIN + item.detail.head_pic
                : item.detail && item.detail.sex == 1
                ? "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png"
                : "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx2.png"
            }" alt="" />
          </div>
          <p>${
            item.detail && item.detail.nick_name
              ? item.detail.nick_name
              : "微风"
          }</p>
        </div>
        <div class="right">${item.all_luxury}</div>
      </div>`;
        } else {
          return `   <div class="list">
        <div class="left"><div class="box">${index + 1}</div></div>
        <div class="center">
          <div class="centerin">
          <img src="${
            item.detail && item.detail.head_pic
              ? IMG_DOMAIN + item.detail.head_pic
              : item.detail && item.detail.sex == 1
              ? "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png"
              : "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx2.png"
          }" alt="" />
          </div>
          <p>${
            item.detail && item.detail.nick_name
              ? item.detail.nick_name
              : "微风"
          }</p>
        </div>
        <div class="right">${item.all_luxury}</div>
      </div>`;
        }
      })
      .join(" ");
    ele.list_son.innerHTML = newList;
    // !渲染我的信息
  }
})();
